(function($) {
    $.fn.extend({
        "clickOutside": function(fun) {
            if(!this[0]){
                console.log('No corresponding element was found')
                return
            }
            if(typeof fun !== 'function'){
                console.log('No callbacks have been added')
                return
            }
            var self = this
            window.addEventListener('click',listenerClick,false)
            function listenerClick(e){
                var flag = false
                for(var i = 0; i<self.length; i++){
                    if($.contains(self[i],e.target)){
                        flag = true
                        return
                    }
                }
                if(!flag){
                    fun()
                }
            }
        }
    });
})(jQuery);
